<template>
  <div class="login-main-wrap">
    <div class="login-main wrapper">
      <div class="login-box">
        <el-form  ref="user" :model="user" label-width="80px">
          <div class="box-hd">
            <span class="tit">用户登录</span>
            <router-link tag="a" to="/sign">注册新账号</router-link>
          </div>
          <el-form-item class="txtin-box" label="用户名">
            <span class="ico user"></span>
            <el-input v-model="user.userName"  placeholder="用户名/手机"></el-input>
          </el-form-item>
          <el-form-item class="txtin-box" label="密码">
            <span class="ico user"></span>
            <el-input v-model="user.password" type="password"  placeholder="密码"></el-input>
          </el-form-item>
          <div class="clearfix tool">
            <a class="find" href="">忘记密码？</a>
          </div>
          <el-button class="tj" type="primary" @click="onSubmit">登录</el-button>
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>
import axios from 'axios'
export default {
  name: 'LoginWrap',
  data () {
    return {
      user: {
        userName: '',
        password: ''
      },
      param: {
        authRequest: {}
      }
    }
  },
  methods: {
    onSubmit () {
      this.param.authRequest = this.user
      axios.post('/java/api/auth', this.user).then(res => {
        if (res.data.status === 0) {
          let data = res.data.data
          this.$cookies.set('CHANGFENG-USER', data.token, 60 * 60 * 24 * 7)
          this.$router.push('/index')
        } else {
          alert(res.data.msg)
        }
      })
    }
  },
  mounted () {
  }
}
</script>
<style>
</style>
